<? if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class user_model extends CI_Model
{
	function __construct() 
	{
		parent::__construct();
	}
	
	function get_all($num=20,$start=0)
	{
		$this->db->where('bl_active',1) ;
		$query = $this->db->get('member', $num, $start) ;
		return $query->result() ;
	}
	
	function count_all()
	{
		$this->db->where('bl_active',1) ;
		$query = $this->db->get('member') ;
		return $query->num_rows() ;
	}
	
	function get_id($id)
	{
		$this->db->where('member_id',$id) ;
		//$this->db->where('bl_active',1) ;
		$query = $this->db->get('member') ;
		return $query->row() ;
	}
	
	function save($req, $id=0)
	{
		if(!empty($id))
		{
			$this->db->where('member_id', $id) ;
			return $this->db->update('member', $req) ;
		}
		else
		{
			$this->db->insert('member', $req) ;
			return $this->db->insert_id() ;
		}
	}
	
	/*function del($table, $where, $id=0)
	{
		if($id) $this->db->where($where, $id);
		return $this->db->delete($table) ;
	}*/
	
	function del($table, $where, $id=0)
	{
		$data['bl_active'] = -1 ;
		$data['dt_modify'] = date("Y-m-d H:i:s") ;
		if($id) $this->db->where($where, $id);
		return $this->db->update($table, $data) ;
	}
	
	function remove($table)
	{
		$date = new DateTime();
		$date->modify('-3 month');
		$date_del = $date->format('Y-m-d H:i:s');
		
		$this->db->where('bl_active', -1);
		$this->db->where('dt_modify <', $date_del);
		return $this->db->delete($table) ;
	}
}
?>